﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WxTenpay.Service.Model;

namespace WxTenpay.Service.Service
{
    /// <summary>
    /// 单位信息
    /// </summary>
    public class SysCompany : BaseService<SysCompanyEntity>, ISysCompany
    {

        public IEnumerable<object> GetCompanyTree()
        {

           var lis= Db.Queryable<SysCompanyEntity>().ToList();
            var Depalis = Db.Queryable<SysDepartmentEntity>().ToList();


            return lis.Select(x =>
            {
                return new
                {
                    value=x.GuId,
                    label=x.CompanyName,
                    children= Depalis.Where(p=>p.CompanyGuId==x.GuId).Select(p=> {
                        return new
                        {
                            value = p.GuId,
                            label = p.DepartmentName,
                        };
                    })
                };

            });




        }

    }
}
